"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
if (!Math) {
  LoginPopup();
}
const LoginPopup = () => "../../components/LoginPopup.js";
const _sfc_main = {
  __name: "mine",
  setup(__props) {
    const userInfo = common_vendor.ref({
      isLogin: false,
      avatar: "",
      nickname: "未登录",
      desc: "登录后享受更多服务"
    });
    const userStats = common_vendor.ref([
      { type: "course", num: "0", label: "我的课程" },
      { type: "collect", num: "0", label: "收藏" },
      { type: "point", num: "0", label: "积分" }
    ]);
    const featureList = common_vendor.ref([
      [
        {
          type: "learning",
          name: "学习记录",
          icon: "📚",
          bgColor: "#007aff20"
        },
        {
          type: "download",
          name: "离线缓存",
          icon: "📥",
          bgColor: "#52c41a20"
        },
        {
          type: "notes",
          name: "BI分析",
          icon: "📝",
          bgColor: "#ff6b6b20"
        }
      ],
      [
        {
          type: "feedback",
          name: "意见反馈",
          icon: "💡",
          bgColor: "#faad1420"
        },
        {
          type: "about",
          name: "关于我们",
          icon: "🏢",
          bgColor: "#13c2c220"
        }
      ]
    ]);
    const showLogin = common_vendor.ref(false);
    const goToLogin = () => {
      if (!userInfo.value.isLogin) {
        showLogin.value = true;
      }
    };
    const goToSetting = () => {
      common_vendor.index.navigateTo({
        url: "/pages/setting/setting"
      });
    };
    const handleFeature = (type) => {
      switch (type) {
        case "learning":
          common_vendor.index.navigateTo({ url: "/pages/learning/record" });
          break;
        case "download":
          common_vendor.index.navigateTo({ url: "/pages/download/list" });
          break;
        case "notes":
          common_vendor.index.navigateTo({ url: "/pages/notes/list" });
          break;
        case "feedback":
          common_vendor.index.navigateTo({ url: "/pages/feedback/index" });
          break;
        case "about":
          common_vendor.index.navigateTo({ url: "/pages/about/index" });
          break;
      }
    };
    const goToDetail = (type) => {
      const urls = {
        course: "/pages/mine/course",
        collect: "/pages/mine/collect",
        point: "/pages/mine/point"
      };
      if (urls[type]) {
        common_vendor.index.navigateTo({ url: urls[type] });
      }
    };
    const handleLogout = () => {
      common_vendor.index.showModal({
        title: "提示",
        content: "确定要退出登录吗？",
        success: async (res) => {
          if (res.confirm) {
            try {
              common_vendor.index.showLoading({
                title: "退出中..."
              });
              await utils_api.userApi.logout();
              common_vendor.index.removeStorageSync("JSESSIONID");
              common_vendor.index.removeStorageSync("userInfo");
              common_vendor.index.removeStorageSync("studyRecords");
              common_vendor.index.removeStorageSync("currentCourse");
              common_vendor.index.removeStorageSync("currentChapter");
              userInfo.value = {
                isLogin: false,
                avatar: "",
                nickname: "未登录",
                desc: "登录后享受更多服务"
              };
              userStats.value = [
                { type: "course", num: "0", label: "我的课程" },
                { type: "collect", num: "0", label: "收藏" },
                { type: "point", num: "0", label: "积分" }
              ];
              common_vendor.index.showToast({
                title: "已退出登录",
                icon: "success"
              });
              common_vendor.index.switchTab({
                url: "/pages/index/index"
              });
            } catch (error) {
              console.error("退出登录失败:", error);
              common_vendor.index.showToast({
                title: "退出失败，请重试",
                icon: "none"
              });
            } finally {
              common_vendor.index.hideLoading();
            }
          }
        }
      });
    };
    const handleLoginSuccess = (info) => {
      userInfo.value = info;
      userStats.value = [
        { type: "course", num: "3", label: "我的课程" },
        { type: "collect", num: "1", label: "收藏" },
        { type: "point", num: "100", label: "积分" }
      ];
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: userInfo.value.avatar || "/static/avatar/default-avatar.png",
        b: !userInfo.value.isLogin
      }, !userInfo.value.isLogin ? {
        c: common_vendor.o(goToLogin)
      } : {
        d: common_vendor.t(userInfo.value.nickname),
        e: common_vendor.t(userInfo.value.desc)
      }, {
        f: common_vendor.o(goToSetting),
        g: common_vendor.f(userStats.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.num),
            b: common_vendor.t(item.label),
            c: index,
            d: common_vendor.o(($event) => goToDetail(item.type), index)
          };
        }),
        h: common_vendor.f(featureList.value, (group, groupIndex, i0) => {
          return {
            a: common_vendor.f(group, (item, index, i1) => {
              return {
                a: common_vendor.t(item.icon),
                b: item.bgColor,
                c: common_vendor.t(item.name),
                d: index,
                e: common_vendor.o(($event) => handleFeature(item.type), index)
              };
            }),
            b: groupIndex
          };
        }),
        i: userInfo.value.isLogin
      }, userInfo.value.isLogin ? {
        j: common_vendor.o(handleLogout)
      } : {}, {
        k: common_vendor.o(handleLoginSuccess),
        l: common_vendor.o(($event) => showLogin.value = $event),
        m: common_vendor.p({
          modelValue: showLogin.value
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7c2ebfa5"]]);
wx.createPage(MiniProgramPage);
